<template>
  <div class="set-admin-home-links-add">
    <w-nav-bar
      :title="isEdit ? '编辑HomeLinks' : '添加HomeLinks'"/>
    <group>
      <x-input
        title="标题"
        placeholder="请输入标题"
        v-model="model.title"/>
    </group>
    <group>
      <x-textarea
        title="链接"
        placeholder="请输入链接"
        v-model="model.link"/>
    </group>
    <w-bottom-btn
      :model="model"
      :btn1-title="isEdit ? '删除' : ''"
      dispose-parameter1="title"
      @click2="okBtnClick"/>
  </div>
</template>

<script>
  import HomeLinksModel from '@/models/web/HomeLinksModel'
  import WBottomBtn from '@/components/mobile/confirmBottomBtn'
  import { Group, XInput, XTextarea } from 'vux'
  export default {
    name: "SetAdminHomeLinksAdd",
    components: {
      WBottomBtn,
      Group, XInput, XTextarea
    },
    data() {
      return {
        /**
         * 模型数据
         */
        model: new HomeLinksModel()
      }
    },
    computed: {
      /**
       * 是否是编辑模式
       */
      isEdit() {
        return this.$route.query.id
      }
    },
    methods: {
      /**
       * 获取详情数据
       */
      getDetail() {
        if (this.$route.query.id) {
          this.model._id = this.$route.query.id
          this.model.getDetail().then(() => {}).catch(() => {})
        }
      },
      /**
       * 确定按钮点击
       */
      okBtnClick(callback) {
        this.$w_check_form(this.model, [
          {
            key: 'title',
            msg: '请填写标题'
          }
        ], callback)
      },
    },
    mounted() {
      this.getDetail()
    }
  }
</script>

<style lang="scss" scoped>
  .set-admin-home-links-add {
  }
</style>
